package com.vhall.component.dao.interactive;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vhall.component.entity.interactive.vo.QuestionListDTO;
import com.vhall.component.entity.room.RoomQuestionLkEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * @author guoxin.wang
 * @date 2021-05-11
 */
@Mapper
@Repository
public interface RoomQuestionLkMapper extends BaseMapper<RoomQuestionLkEntity> {

    /**
     * 判断问卷是否发布
     *
     * @param questionId 问卷id
     * @return 返回值
     */
    Integer questionIsPublish(Integer questionId);

    /**
     * 统计问卷数量
     *
     * @param roomId    房间id
     * @param accountId 用户id
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @return 返回值
     */
    Integer countQuestionNum(@Param("roomId") String roomId, @Param("accountId") Integer accountId,
                             @Param("beginDate") String beginDate, @Param("endDate") String endDate);

    /**
     * 分页查询明细
     *
     * @param page         分页信息
     * @param queryWrapper 查询条件
     * @return 问卷列表
     */
    @Select("select q.*, lk.updated_at AS lk_update_time, lk.publish, lk.room_id from questions q "
            + "left join room_question_lk lk on q.question_id = lk.question_id ${ew.customSqlSegment}")
    Page<QuestionListDTO> selectQuestionDetailInRoomPage(Page<QuestionListDTO> page,
                                                         @Param(Constants.WRAPPER) Wrapper<QuestionListDTO> queryWrapper);

}
